
package com.ruoyi.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.bo.PageResponse;
import com.ruoyi.common.tenant.helper.TenantHelper;
import com.ruoyi.system.domain.Form;
import com.ruoyi.system.mapper.FormMapper;
import com.ruoyi.system.service.IFormService;

import jakarta.annotation.Resource;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FormServiceImpl implements IFormService {

    @Resource
    private FormMapper formMapper;

    @Override
    public PageResponse<Form> selectFormList(Form form, Integer pageNum, Integer pageSize) {
        if (form == null) {
            form = new Form();
        }
        form.setTenantId(TenantHelper.getTenantId());
        int total = formMapper.selectFormCount(form);
        PageHelper.startPage(pageNum, pageSize, false); // 第三个参数为 false 表示不执行 COUNT
        List<Form> forms = formMapper.selectFormList1(form, (pageNum - 1) * pageSize, pageNum * pageSize);
        return new PageResponse<Form>(forms, total);
    }

    @Override
    public Form selectFormById(Long id) {
        return formMapper.selectFormById(id);
    }

    @Override
    public int insertForm(Form form) {
        return formMapper.insertForm(form);
    }

    @Override
    public int updateForm(Form form) {
        return formMapper.updateForm(form);
    }

    @Override
    public int deleteFormById(Long id) {
        return formMapper.deleteFormById(id);
    }

    @Override
    public Form selectFormByName(String formName, Long tenantId) {
        return formMapper.selectFormByName(formName, tenantId);
    }
}
